package com.tql.mall.order.config;

import com.tql.mall.rabbit.constant.MqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @Author: tyk
 * @Date: 2023/5/27 11:36
 * @Description:
 */
@Configuration
public class OrderMqConfig {
    /**
     * 超时取消订单消息队列
     */
    @Bean
    public CustomExchange cancelExchange() {
        HashMap<String, Object> param = new HashMap<String, Object>() {{
            put("x-delayed-type", "direct");
        }};
        return new CustomExchange(MqConstant.EXCHANGE_ORDER_CANCEL, "x-delayed-message", true, false, param);
    }

    @Bean
    public Queue cancelQueue() {
        return new Queue(MqConstant.QUEUE_ORDER_CANCEL, true);
    }

    @Bean
    public Binding cancelBinding() {
        return BindingBuilder.bind(cancelQueue()).to(cancelExchange()).with(MqConstant.ROUTING_ORDER_CANCEL).noargs();
    }


    /**
     * 支付模块的消息队列
     */

    @Bean
    public DirectExchange payExchange() {
        return new DirectExchange(MqConstant.EXCHANGE_PAY, true, false);
    }

    @Bean
    public Queue payQueue() {
        return new Queue(MqConstant.QUEUE_PAY, true);
    }

    @Bean
    public Binding payBinding() {
        return BindingBuilder.bind(payQueue()).to(payExchange()).with(MqConstant.ROUTING_PAY);
    }

}
